package com.dingyx.ps.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dingyuxin
 *
 */
@Slf4j
public class CommonUtils {
    public static <T> List<T> copyList(List originList,Class<T> tClass){
        List<T> list = new ArrayList<>();
        if(CollectionUtil.isEmpty(originList)){
            return list;
        }
        for (Object item : originList) {
            T bean;
            try {
                bean = tClass.newInstance();
                BeanUtils.copyProperties(item, bean);
                list.add(bean);
            } catch (InstantiationException e) {
                log.error(ExceptionUtil.getMessage(e));
            } catch (IllegalAccessException e) {
                log.error(ExceptionUtil.getMessage(e));
            }
        }
        return list;
    }
}
